import 'package:flutter/material.dart';

class ClipPathDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        ClipPath(
          // 路径裁切组件
          clipper: BottomCliper(),
          child: Container(
            height: 200.0,
            color: Colors.amberAccent,
          ),
        ),
      ],
    );
  }
}

class BottomCliper extends CustomClipper<Path> {
  @override
  Path getClip(Size size) {
    // ClipPath子元素的size
    var path = Path(); // 画一条路径
    path.lineTo(0, 0);
    path.lineTo(0, size.height - 50);
    var pointerStart = Offset(size.width / 2, size.height); // 贝塞尔曲线点
    var pointerEnd = Offset(size.width, size.height - 50); // 贝塞尔曲线点
    path.quadraticBezierTo(
        // 贝塞尔曲线
        pointerStart.dx,
        pointerStart.dy,
        pointerEnd.dx,
        pointerEnd.dy);
    path.lineTo(size.width, size.height - 50);
    path.lineTo(size.width, 0);
    return path; // 返回路径
  }

  @override
  bool shouldReclip(CustomClipper<Path> oldClipper) {
    return false; // 必须复写那么直接返回false
  }
}
